import { minapi } from "./MiniApi";


export class MiniApiAudioSource {
    protected audioSource: WechatMinigame.InnerAudioContext | null;
    /**
     *
     * @param uri 填相对$projectDir/build-templates/wechatgame相对路径
     */
    constructor(uri: string | null = null) {
        this.audioSource = minapi.createInnerAudioContext();
        if (this.audioSource != null) {
            this.audioSource.src = uri!;
        }
    }
    /**
     * 填相对$projectDir/build-templates/wechatgame相对路径
     */
    set src(uri: string | undefined) {
        if (this.audioSource != null) {
            this.audioSource.src = uri!;
        }
    }
    get src(): string | undefined {
        if (this.audioSource != null) {
            return this.audioSource.src;
        }
        return undefined;
    }
    play() {
        if (this.audioSource != null) {
            this.audioSource.play();
        }
    }
    stop() {
        if (this.audioSource != null) {
            this.audioSource.stop();
        }
    }
    pause() {
        if (this.audioSource != null) {
            this.audioSource.pause();
        }
    }
}
